<?php

use App\Enums\AccountTypes;
use App\Http\Controllers\Auth\AuthController;
use App\Http\Controllers\Auth\DashboardController;
use App\Http\Controllers\Auth\GroupController;
use App\Http\Controllers\Auth\PasswordController;
use App\Http\Controllers\Auth\ProfileController;
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;

Route::get('auth/{accountType}/login', [AuthController::class, 'index'])->whereIn('accountType', AccountTypes::cases())->name('login');

Route::group(['prefix' => 'auth/{accountType}', 'as' => 'auth.'], function() {
    // 注册、登陆、退出
    Route::controller(AuthController::class)->group(function() {

        Route::post('login', 'postLogin')->name('login.post');
        Route::get('registration', 'registration')->name('register');
        Route::post('registration', 'postRegistration')->name('register.post');
        Route::get('logout', 'logout')->middleware(['auth:user', 'set.team.id:user'])->name('logout');
    });
    // 会员中心
    Route::middleware(['auth:user', 'set.team.id:user'])->group(function() {

        Route::get('dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');

        Route::controller(PasswordController::class)->prefix('password')->group(function() {
            Route::get('change', 'changePassword')->name('password.change');
            Route::post('update', 'update')->name('password.update');
        });

        Route::controller(GroupController::class)->group(function() {
            Route::get('group',  'index')->name('group');
            Route::get('buy/group',  'buy')->name('buy.group');
        });

        Route::get('profile', [ProfileController::class, 'index'])->name('profile');

    });
})->whereIn('accountType', AccountTypes::cases());

Route::get('/', [HomeController::class, 'index'])->name('home');
